package com.example.demo.lc;

/**
 * @Description 动态规划
 * @Author wzh
 * @Date 2022/6/10 11:12 下午
 * @Version 1.0
 */
public class Leetcode53 {
    public static void main(String[] args) {
        int[] nums = {-2,1,-3,4,-1,2,1,-5,4};
        System.out.println(maxSubArray(nums));
    }

    public static int maxSubArray(int[] nums) {
        int pre = 0;
        int max = nums[0];
        for (int i = 0; i < nums.length; i++) {
            pre = Math.max(pre+nums[i],nums[i]);
            max = Math.max(max,pre);
        }
        return max;
    }
}
